<form id="adSpaceForm" class="form-horizontal" action="${ctx}/admin/ad/saveAdSpace.do"  method="post">
    <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal">&times;</button>
        <h5 class="blue">编辑广告位</h5>
    </div>
    <input type="hidden" name="id" id="id" class="col-xs-12 col-sm-4 required" value="${adSpace.id!}"/>
    <div class="modal-body">
        <div class="form-group">
            <label class="control-label col-xs-12 col-sm-3 no-padding-right" for="adSpaceName">广告位名称:</label>
            <div class="col-xs-12 col-sm-9">
                <div class="clearfix">
                    <input type="text" name="adSpaceName" id="adSpaceName" class="col-xs-12 col-sm-4 required" value="${adSpace.adSpaceName!}"/>
                </div>
            </div>
        </div>

        <div class="form-group">
            <label class="control-label col-xs-12 col-sm-3 no-padding-right" for="terminalId">展示终端:</label>
            <div class="col-xs-12 col-sm-9">
                    <div class="clearfix">
                        <select class="input-medium" id="terminalId" name="terminalId">
                            <#list terminalList as t>
                                <option value="${t.id!}" >${t.terminalName!}</option>
                            </#list>
                        </select>
                    </div>
            </div>
        </div>

        <!--展示类型-->
        <div class="form-group">
            <label class="control-label col-xs-12 col-sm-3 no-padding-right" for="spaceShowType">展示类型:</label>
            <div class="col-xs-12 col-sm-9">
                <div class="clearfix">
                    <select class="input-medium" id="spaceShowType" name="spaceShowType">
                        <#list showTypes as showType>
                            <option value="${showType.id}" >
                                ${(showType.name)!}
                            </option>
                        </#list>
                    </select>
                </div>
            </div>
        </div>

        <div class="form-group">
            <label class="control-label col-xs-12 col-sm-3 no-padding-right">状态:</label>
            <div class="col-xs-12 col-sm-9">
                <div class="clearfix">
                    <select class="input-medium" id="state" name="state">
                        <option value="1" <#if adSpace.state?? && adSpace.state = 1>selected="selected"</#if>>显示</option>
                        <option value="0" <#if adSpace.state?? && adSpace.state = 0>selected="selected"</#if>>隐藏</option>
                        <option value="-1" <#if adSpace.state?? && adSpace.state = -1>selected="selected"</#if>>删除</option>
                    </select>
                </div>
            </div>
        </div>

        <div class="hr hr-dotted"></div>

        <div class="form-group">
            <label class="control-label col-xs-12 col-sm-3 no-padding-right" for="sortIndex">显示顺序:</label>
            <div class="col-xs-12 col-sm-9">
                <div class="clearfix">
                    <span class="input-icon input-icon-right">
                        <input type="sortIndex" name="sortIndex" id="sortIndex" value="${adSpace.sortIndex!}" />
                    </span>
                </div>
            </div>
        </div>

        <div class="form-group">
            <label class="control-label col-xs-12 col-sm-3 no-padding-right" for="picWidth">图片宽度:</label>
            <div class="col-xs-12 col-sm-9">
                <div class="clearfix">
                    <span class="input-icon input-icon-right">
                        <input type="picWidth" name="picWidth" id="picWidth" value="${adSpace.picWidth!}" />
                    </span>
                </div>
            </div>
        </div>

        <div class="form-group">
            <label class="control-label col-xs-12 col-sm-3 no-padding-right" for="picHeight">图片高度:</label>
            <div class="col-xs-12 col-sm-9">
                <div class="clearfix">
                    <span class="input-icon input-icon-right">
                        <input type="picHeight" name="picHeight" id="picHeight" value="${adSpace.picHeight!}" />
                    </span>
                </div>
            </div>
        </div>

        <div class="form-group">
            <label class="control-label col-xs-12 col-sm-3 no-padding-right" for="adLimit">广告个数限制:</label>
            <div class="col-xs-12 col-sm-9">
                <div class="clearfix">
                    <span class="input-icon input-icon-right">
                        <input type="adLimit" name="adLimit" id="adLimit" value="${adSpace.adLimit!}" />
                    </span>
                </div>
            </div>
        </div>
    </div>

    <div class="modal-footer center">
        <button type="submit" class="btn btn-sm btn-success"><i class="ace-icon fa fa-check"></i> 保存</button>
        <button type="button" class="btn btn-sm" data-dismiss="modal"><i class="ace-icon fa fa-times"></i> 取消</button>
    </div>
</form>
<script src="${ctx}/static/admin/assets/js/jquery.validate.js"></script>
<script src="${ctx}/static/admin/assets/js/jquery.validate.messages_zh.js"></script>
<script src="${ctx}/static/admin/assets/js/ajaxfileupload.js"></script>

<script type="text/javascript">
    $(document).ready(function(){
        $("#spaceShowType").val(${adSpace.spaceShowType!});

        $(".date-picker").datepicker({
            language : 'zh-CN',
            autoclose: true,
            todayHighlight: true
        });

        $("#adSpaceForm").validate({
            errorElement: 'div',
            errorClass: 'help-block',
            focusInvalid: true,
            highlight: function (e) {
                $(e).closest('.form-group').removeClass('has-info').addClass('has-error');
            },
            success: function (e) {
                $(e).closest('.form-group').removeClass('has-error');//.addClass('has-info');
                $(e).remove();
            },
            errorPlacement: function (error, element) {
                if(element.is('input[type=checkbox]') || element.is('input[type=radio]')) {
                    var controls = element.closest('div[class*="col-"]');
                    if(controls.find(':checkbox,:radio').length > 1) controls.append(error);
                    else error.insertAfter(element.nextAll('.lbl:eq(0)').eq(0));
                }
                else if(element.is('.select2')) {
                    error.insertAfter(element.siblings('[class*="select2-container"]:eq(0)'));
                }
                else if(element.is('.chosen-select')) {
                    error.insertAfter(element.siblings('[class*="chosen-container"]:eq(0)'));
                }
                else error.insertAfter(element.parent());
            },

            submitHandler: function (form) {
                $.ajax({
                    cache: true,
                    type: "POST",
                    url:"${ctx}/admin/ad/saveAdSpace.do",
                    data:$('#adSpaceForm').serialize(),// 你的formid
                    async: false,
                    error: function(request) {
                        alert("Connection error");
                    },
                    success: function(data) {
                        if(data.result == "success"){
                            window.location="${refer!}";
                        }else{
                            alert(data.messages);
                        }
                    }
                });
            },
            invalidHandler: function (form) {
            }
        })
    });
</script>